<?php
$objCarForm = new BM_PHPForm();
if (isset($_REQUEST['msg'])) {
	$strId = $_REQUEST['id'];
	if ($_REQUEST['msg'] == "infSaved") {
		$objCarForm->SetInfor("submit", "Car Added Successfully !");
	}
	if ($_REQUEST['msg'] == "infDeleted") {
		$objCarForm->SetInfor("delete","Car by id = [$strId] Deleted Successfully!");
	}
	if ($_REQUEST['msg'] == "errDeleted") {
		$objCarForm->SetInfor("delete","Car by id = [$strId] Cann't Be Deleted !");
	}
}

print $objCarForm->InfMsgs();

$num_cars = CarDao::getTotalNumber();
$pager_options = array(
    'mode'       => 'Sliding',
    'perPage'    => 5,
    'delta'      => 2,
    'totalItems' => $num_cars,
);
require_once 'Pager/Pager.php';
$pager = Pager::factory($pager_options);
$cars = CarDao::findAllPaging($pager);
?>
	  <div >
	    <span> 
		<a href="../<?php echo $www;?>/index_admin.php?entity=car&action=new">New Car</a> 
		</span>
	  </div>
	  <div align="center">
			<?php echo $pager->links;?>
	  </div>	
	  <table class="table">
        <tr>
	      <th>ID</th>
	      <th>MAKE</th>
		  <th>MODEL</th>
		  <th>PRICE</th>
		  <th>COLOR</th>
		  <th>PHOTO</th>
		  <th>&nbsp;</th>
		  <th>&nbsp;</th>
		  <th>&nbsp;</th>
	    </tr>
	
	<?php
	if (count($cars) > 0){
		foreach ($cars as $c){
		?>
	    <tr>
		  <td><?php print $c->id?>&nbsp;</td>
		  <td><?php print $c->make?>&nbsp;</td>
		  <td><?php print $c->model?>&nbsp;</td>
		  <td><?php print $c->price?>&nbsp;</td>
		  <td><?php print $c->color?>&nbsp;</td>
		  <td>
		  	<span>
		  		<a href="../<?php echo $www;?>/index_public.php?entity=car&action=details&cid=<?php echo $c->id;?>">
		  		<img width="50px" height="50px" alt="" src="img/cars/_thb_<?php print $c->photo?>"/></a>
		  	</span>
		  </td>
		  <td>
		  	<span>
		  		<a href="../<?php echo $www;?>/index_public.php?entity=car&action=details&cid=<?php echo $c->id;?>">Details</a>
		  	</span>
		  </td>
		  <td>
		  	<span>
			  <a href="../<?php echo $www;?>/index_admin.php?entity=car&amp;action=update&amp;id=<?php print $c->id?>">Edit</a>
		  	</span>
		  </td>
		  <td>
			<span>
			  <a href="javascript:deleteObjectByAdmin('<?php print $c->id?>','car')">Delete</a>
			</span>
		  </td>
	    </tr>
	
		<?php
		}
	
	}
	?>
 	  </table>
	  <div align="center">
			<?php echo $pager->links;?>
	  </div>	